package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.SysAssetMaintenanceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysAssetMaintenance;
import com.ruoyi.system.service.ISysAssetMaintenanceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 资产维护保养Controller
 * 
 * @author sxy
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/maintenance")
public class SysAssetMaintenanceController extends BaseController
{
    @Autowired
    private ISysAssetMaintenanceService sysAssetMaintenanceService;

    /**
     * 查询资产维护保养列表
     */
    @RequiresPermissions("system:maintenance:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAssetMaintenance sysAssetMaintenance)
    {
        startPage();
        List<SysAssetMaintenanceVo> list = sysAssetMaintenanceService.selectSysAssetMaintenanceList(sysAssetMaintenance);
        return getDataTable(list);
    }

    /**
     * 导出资产维护保养列表
     */
    @RequiresPermissions("system:maintenance:export")
    @Log(title = "资产维护保养", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAssetMaintenance sysAssetMaintenance)
    {
        List<SysAssetMaintenanceVo> list = sysAssetMaintenanceService.selectSysAssetMaintenanceList(sysAssetMaintenance);
        ExcelUtil<SysAssetMaintenanceVo> util = new ExcelUtil<SysAssetMaintenanceVo>(SysAssetMaintenanceVo.class);
        util.exportExcel(response, list, "资产维护保养数据");
    }

    /**
     * 获取资产维护保养详细信息
     */
    @RequiresPermissions("system:maintenance:query")
    @GetMapping(value = "/{maintenanceId}")
    public AjaxResult getInfo(@PathVariable("maintenanceId") Long maintenanceId)
    {
        return success(sysAssetMaintenanceService.selectSysAssetMaintenanceByMaintenanceId(maintenanceId));
    }

    /**
     * 新增资产维护保养
     */
    @RequiresPermissions("system:maintenance:add")
    @Log(title = "资产维护保养", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAssetMaintenance sysAssetMaintenance)
    {
        return toAjax(sysAssetMaintenanceService.insertSysAssetMaintenance(sysAssetMaintenance));
    }

    /**
     * 修改资产维护保养
     */
    @RequiresPermissions("system:maintenance:edit")
    @Log(title = "资产维护保养", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAssetMaintenance sysAssetMaintenance)
    {
        return toAjax(sysAssetMaintenanceService.updateSysAssetMaintenance(sysAssetMaintenance));
    }

    /**
     * 删除资产维护保养
     */
    @RequiresPermissions("system:maintenance:remove")
    @Log(title = "资产维护保养", businessType = BusinessType.DELETE)
	@DeleteMapping("/{maintenanceIds}")
    public AjaxResult remove(@PathVariable Long[] maintenanceIds)
    {
        return toAjax(sysAssetMaintenanceService.deleteSysAssetMaintenanceByMaintenanceIds(maintenanceIds));
    }
}
